#include "fastrpc/rpc.hpp"
#include "order.pb.h"
using namespace fastrpc::log;
using namespace fastrpc::io;
using namespace fastrpc::net;
using namespace fastrpc::async;
using namespace fastrpc;
using namespace fastrpc::rpc;
auto client() -> Task<void> {
    auto res = co_await RpcClient::GetInstance("127.0.0.1", 10000);
    if (!res) {
        console.error("{}", res.error().message());
        co_return;
    }
    auto             client = std::move(res.value());
    makeOrderRequest request1;
    request1.set_price(100);
    request1.set_goods("apple");
    auto result1 = co_await client.call<makeOrderRequest, makeOrderResponse>("1",
                                                                             "Order.makeOrder",
                                                                             std::ref(request1));
    if (result1.ret_code() == -1) {
        console.error("get order failed !!!");
    } else {
        console.info("get order:{}", result1.order_id());
    }

    makeOrderRequest request2;
    request2.set_price(-1);
    request2.set_goods("apple");
    auto result2 = co_await client.call<makeOrderRequest, makeOrderResponse>("2",
                                                                             "Order.makeOrder",
                                                                             std::ref(request2));
    if (result2.ret_code() == -1) {
        console.error("get order failed !!!");
    } else {
        console.info("get order:{}", result2.order_id());
    }
}
int main() {
    SET_LOG_LEVEL(fastrpc::log::LogLevel::Debug);
    auto runtime = fastrpc::runtime::MultiThreadBuilder::options().set_num_workers(3).build();
    runtime.block_on(client());
}
